import type { MesTeam, MesTeamMember } from "@/pages/mes/team/entity";
import apiClient from "../../apiClient";

export interface PageListReq {
  //班组编号
  teamCode?: string;
  //班组名称
  teamName?: string;
  //班组类型
  teamType?: string;
  //当前页码
  page: number;
  //每页数量
  pageSize: number;
}

export interface PageListRes {
  //总记录数
  total: number;
  //数据列表
  records: MesTeam[];
}

const pageList = (data: PageListReq): Promise<PageListRes> =>
  apiClient.post({
    url: "/mes/team/pageList",
    data
});
const getInfo = (id: React.Key): Promise<MesTeam> =>
  apiClient.get({
    url: `/mes/team/${id}`
});

const add = (data: MesTeam): Promise<MesTeam> =>
  apiClient.post({
    url: "/mes/team",
    data
});

const update = (data: MesTeam): Promise<MesTeam> =>
  apiClient.put({
    url: "/mes/team",
    data
});

const remove = (ids: React.Key[]): Promise<void> =>
  apiClient.delete({
    url: "/mes/team",
    params: {
    ids: ids.join(",")
  }
});
const getTeamMembers = (id: React.Key): Promise<MesTeamMember[]> =>
  apiClient.post({
    url: "/mes/team/member/list",
    data: {
      teamId: id
    }
  });

export const mesTeamService = {
  pageList,
  getInfo,
  add,
  update,
  remove,
  getTeamMembers,
};

export default mesTeamService;